1
'****************************** Module Header ******************************'
2 ' Module Name: MainPage.xaml.vb
4 ' Copyright (c) Microsoft Corporation.
6 ' This example demonstrates how to work with text in Silverlight using VB.
8 ' This source is subject to the Microsoft Public License.
9 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 ' All other rights reserved.
12 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 '***************************************************************************'
18 Partial
Public Class MainPage
25 Private Sub UserControl_Loaded(ByVal sender
As System
.Object, ByVal e
As System
.Windows
.RoutedEventArgs
)
26 Me.CreateSimpleTextBlock()
27 Me.CreateComplexTextBlock()
32 ''' This method creates a simple TextBlock, and adds it to the StackPanel
33 ''' simpleTBPlaceHolder.
35 ''' <remarks></remarks>
36 Private Sub CreateSimpleTextBlock()
37 Dim simpleTextBlock
= New TextBlock()
38 simpleTextBlock
.Text
= "Simple TextBlock"
39 Me.simpleTBPlaceHolder
.Children
.Add(simpleTextBlock
)
43 ''' This method creates a TextBlock with multiple Runs and LineBreaks,
44 ''' and adds it to the StackPanel complexTBPlaceHolder.
46 ''' <remarks></remarks>
47 Private Sub CreateComplexTextBlock()
48 Dim complexTextBlock
= New TextBlock()
49 Dim paragraph1
= New Run()
50 paragraph1
.Text
= "Paragraph1"
51 Dim lineBreak
= New LineBreak()
52 Dim paragraph2
= New Run()
53 paragraph2
.Text
= "Paragraph2"
54 complexTextBlock
.Inlines
.Add(paragraph1
)
55 complexTextBlock
.Inlines
.Add(lineBreak
)
56 complexTextBlock
.Inlines
.Add(paragraph2
)
57 Me.complexTBPlaceHolder
.Children
.Add(complexTextBlock
)
61 ''' This method creates a TextBlock with advanced format, and adds it to
62 ''' the StackPanel customizeFormatPlaceHolder.
64 ''' <remarks></remarks>
65 Private Sub FormatText()
66 Dim formatTextBlock
= New TextBlock()
67 Dim paragraph1
= New Run()
68 paragraph1
.Text
= "Paragraph1"
69 paragraph1
.FontFamily
= New FontFamily("Magnetob.ttf#Magneto")
70 Dim lineBreak
= New LineBreak()
71 Dim paragraph2
= New Run()
72 paragraph2
.Text
= "Paragraph2"
73 Dim brush
= New LinearGradientBrush()
74 Dim stop1
= New GradientStop()
75 stop1
.Color
= Colors
.Blue
77 brush
.GradientStops
.Add(stop1
)
78 Dim stop2
= New GradientStop()
79 stop2
.Color
= Colors
.Red
81 brush
.GradientStops
.Add(stop2
)
82 paragraph2
.Foreground
= brush
83 formatTextBlock
.Inlines
.Add(paragraph1
)
84 formatTextBlock
.Inlines
.Add(lineBreak
)
85 formatTextBlock
.Inlines
.Add(paragraph2
)
86 Me.customizeFormatPlaceHolder
.Children
.Add(formatTextBlock
)
90 ''' This method selects all text in the TextBox targetTextBox. Note you
91 ''' have to focus the TextBox so that the selection will be displayed.
93 ''' <param name="sender"></param>
94 ''' <param name="e"></param>
95 ''' <remarks></remarks>
96 Private Sub selectTextButton_Click(ByVal sender
As Object, ByVal e
As RoutedEventArgs
)
97 Me.targetTextBox
.SelectAll()
98 Me.targetTextBox
.Focus()